import { getRoadList } from '@/api/home/map/road'

export function getRoadName (code) {
  let result = ''
  if (code == null || code === '' || !getRoadListAll()) return result
  getRoadListAll().some(function (item) {
    if (item.roadId === code) {
      result = item.name
      return true
    }
  })
  return result
}
export function getRoadListAll () {
  var roadListAll = JSON.parse(localStorage.getItem('roadListAll'))
  if (!roadListAll || roadListAll.length === 0) {
    setRoadListAll()
    return JSON.parse(localStorage.getItem('roadListAll'))
  }
  return roadListAll
}
export async function setRoadListAll () {
  await getRoadList().then(response => {
    const { data } = response
    if (data) {
      localStorage.setItem('roadListAll', JSON.stringify(data))
    }
  })
}
export function removeRoadListAll () {
  localStorage.removeItem('roadListAll')
}
